<template>
	<view class="oldSearchContent">
		<view class="list" v-for="item in searchResult" @click="searchList(item)">
			<view class="icon"></view>
			<view class="wb">{{item.title}}</view>
			<view class="clear"></view>
		</view>
	</view>
</template>

<script>
	export default{
		props: {
			searchResult: {
				type: Array,
				default: []
			}
		},
		data(){
			return{
			}
		},
		onLoad() {
			var self = this
		},
		methods: {
			// 储存数据
			saveJson(item) {
				var tempResult = false
				if (uni.getStorageSync('serachOldJson')) {
					var temp = uni.getStorageSync('serachOldJson')
					// 去重
					temp.map((v, i) => {
						if(v.title.indexOf(item.title) >= 0) {
							tempResult = true
						}
					})
					if(tempResult) {
						return
					}
					temp.unshift(item)
					if (temp.length > 5) {
						temp.pop()
					}
					uni.setStorageSync('serachOldJson', temp)
				}else {
					uni.setStorageSync('serachOldJson', [item])
				}
			},
			
			// 点击搜索
			searchList(item) {
				var self = this
				self.saveJson(item)
				self.$store.dispatch('searchShow/clickSearchSHow', {
					isShowResult: true,
					value: item
				})
			}
		},
		watch: {
		}
	}
</script>

<style lang="scss" scoped>
	.oldSearchContent {
		width: 100%;
		max-height: 600rpx;
		overflow-y: auto;
		position: absolute;
		top: 74rpx;
		z-index: 99;
		background-color: black;
		.list {
			width: 90%;
			margin-left: 5%;
			display: flex;
			align-items: center;
			height: 40rpx;
			margin-top: 30rpx;
			padding-bottom: 30rpx;
			border-bottom: solid 1rpx #1C1B2B;
			.icon {
				width: 30rpx;
				height: 30rpx;
				background-size: 28rpx;
				background-repeat: no-repeat;
				background-image: url(../icon/search.png);
				background-position: center;
			}
			
			.wb {
				height: 40rpx;
				width: 75%;
				overflow: hidden;
				color: #DDDBFB;
				font-size: 28rpx;
				margin-left: 20rpx;
			}
			
			.clear {
				width: 30rpx;
				height: 30rpx;
				margin-left: 130rpx;
				background-size: 28rpx;
				background-repeat: no-repeat;
				background-image: url(../icon/xjt.png);
				background-position: center;
			}
		}
		
		.noClass {
			margin-top: 150rpx;
			width: 100%;
			text-align: center;
		}
	}
</style>
